﻿<?php
if(!defined('IN_PHPSCUP'))exit('hacking'); 
class CompanyApp extends BaseApp
{
    var $type = 'company';    
    function setting()
    {
       if(!isset($_GET['action']))$_GET['action']='';
	   $action = $_GET['action'];
       if($action=='addpost')
	   {
		$user_id = $GLOBALS['SCup']->SCup_user_msg['user_id'];
	    $TB_company = &$this->_model('company'); 	
	    $companydata = $TB_company->oneshow($user_id);
		$setingconfig = unserialize($companydata['setingconfig']);
						   
	    $data = $_POST['data'];
        if(empty($data['site_url']))
		{
		$data['site_url'] = SITE_URL;
		}
        if(empty($data['upfile_path']))
		{
		$data['upfile_path'] = 'upfiles';
		}		
		if($_FILES['postfile1']['tmp_name'])
	    { 		
	    include(ROOT_PATH.'/lib/upfile.lib.php');	  
		$upfile = new Upfile('company/'.$user_id); 	  
	    $updata = $upfile->_batch_upfile('setting');
		if(!empty($updata)&&isset($updata[1]['path']))
		{
		   if(isset($setingconfig['waterimg_dir'])&&$setingconfig['waterimg_dir'])
		   {
              del_file(ROOT_PATH . '/' . UPFILE_PATH . '/' . $setingconfig['waterimg_dir']);	
		   }
		   $data['waterimg_dir']=$updata[1]['path'];
		}
        } 
		if(!isset($data['register_verycode']))$data['register_verycode']=0;
		if(!isset($data['login_verycode']))$data['login_verycode']=0;

		$TB_set = &$this->_model('setting');	
		$setdata = $TB_set->show();
		$temp_setdata = array();		
		foreach($setdata as $key => $value)
		{
           $temp_setdata[$value['keyname']] = $value['value'];		   
		}
		foreach($setingconfig as $key => $value)
		{
           $temp_setdata[$key] = $value;	   
		}		
		
		foreach($data as $key => $value)
		{
           $temp_setdata[$key] = $value;	   
		}	
			
	    $TB_company->editsetting($user_id,serialize($temp_setdata)); 	 
		$str = '';		 
         foreach ($temp_setdata as $key => $value)
         {
               if (is_string($value) || is_numeric($value) || is_bool($value) || is_null($value))
               {
                    $str .= "define('".strtoupper($key)."','".$value."');\r\n";

                }
         }		 		 	    	
		 write_file(ROOT_PATH . '/data/companyconfig/config_'.$companydata['id'].'.inc.php',"<?php\r\n".$str.'?>');	
	      $notice = &get_message(array('msg'=>'Succes!','url'=>'?app=company&act=setting','title'=>'Notice'));
	      $notice ->display();			 	      	   
	   }	    
		$setingdata =array();
		$data = array();
		$user_id = $GLOBALS['SCup']->SCup_user_msg['user_id'];
		
	    $TB_company = &$this->_model('company'); 	
	    $companydata = $TB_company->oneshow($user_id);
        $data = unserialize($companydata['setingconfig']);

		!isset($data['waterimg_dir'])?$data['waterimg_dir']='':'';
		!isset($data['site_url'])?$data['site_url']='':'';
		!isset($data['site_title'])?$data['site_title']='':'';		
		!isset($data['site_keywords'])?$data['site_keywords']='':'';		
		!isset($data['site_description'])?$data['site_description']='':'';		
		!isset($data['miibeian'])?$data['miibeian']='':'';
		!isset($data['upfile_path'])?$data['upfile_path']='':'';		
		!isset($data['thumb_width'])?$data['thumb_width']='':'';		
		!isset($data['thumb_height'])?$data['thumb_height']='':'';			
		!isset($data['is_waterimg'])?$data['is_waterimg']='':'';
		!isset($data['max_file_size'])?$data['max_file_size']='':'';		
		!isset($data['upfile_types'])?$data['upfile_types']='':'';		
		!isset($data['enabled_gzip'])?$data['enabled_gzip']='':'';			
		!isset($data['system_url_rewrite'])?$data['system_url_rewrite']='':'';	
		!isset($data['system_url_html_rewrite'])?$data['system_url_html_rewrite']='':'';				
		!isset($data['version_info'])?$data['version_info']='':'';			
		!isset($data['system_open'])?$data['system_open']='':'';
		!isset($data['system_open_reason'])?$data['system_open_reason']='':'';		
		!isset($data['allow_register'])?$data['allow_register']='':'';		
		!isset($data['close_register_reason'])?$data['close_register_reason']='':'';			
		!isset($data['login_verycode'])?$data['login_verycode']='':'';		
		!isset($data['register_verycode'])?$data['register_verycode']='':'';		
		!isset($data['lang'])?$data['lang']='':'';		
		!isset($data['cookie_domain'])?$data['cookie_domain']='':'';		
		!isset($data['cookie_path'])?$data['cookie_path']='':'';		
		!isset($data['cookie_secure'])?$data['cookie_secure']='':'';		
		!isset($data['cookie_prefix'])?$data['cookie_prefix']='':'';		
		!isset($data['session_prefix'])?$data['session_prefix']='':'';		
		!isset($data['session_max_life_time'])?$data['session_max_life_time']='':'';
		!isset($data['cache_server'])?$data['cache_server']='':'';		
		!isset($data['user_type'])?$data['user_type']='':'';		
		!isset($data['view_type'])?$data['view_type']='':'';		
		!isset($data['css_type'])?$data['css_type']='':'';		
		!isset($data['enabled_subdomain'])?$data['enabled_subdomain']='':'';		
		!isset($data['subdomain_suffix'])?$data['subdomain_suffix']='':'';		
		!isset($data['system_mysql_session'])?$data['system_mysql_session']='':'';		
		!isset($data['encrypt_key'])?$data['encrypt_key']='':'';	
		!isset($data['away_use_keyword'])?$data['away_use_keyword']='':'';		
		!isset($data['away_use_zhandian'])?$data['away_use_zhandian']='':'';			
		!isset($data['qq_set_data'])?$data['qq_set_data']='':'';		
						
        $this->assign('data', $data);	
		
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
			
        $this->assign('login_icon', $GLOBALS['SCup']->SCup_user_checking);	       
		 $this->assign('langtype', trim($GLOBALS['Lang']->_lang_tp));
	        $this->assign('site_url',SITE_URL);	
		$this->assign('bg_pic_url',SITE_URL.'/'.$GLOBALS['SCup']->SCup_name.'/view/'.VIEW_TYPE .'/style/'.CSS_TYPE.'/');	
		 $this->display('company/companysetting.view.html');

    }

    function companypost()
    {
      if(!isset($_GET['action']))$_GET['action']='';
	  $action = $_GET['action'];
       if($action=='addpost')
	   {
	   
		  $TB_company= &$this->_model('company');		 		 		
		  $companydata = $TB_company->oneshow($GLOBALS['SCup']->SCup_user_msg['user_id']);
          if($companydata['id'])
		  {
	      $notice = &get_message(array('msg'=>'你已经登记过店铺了！','url'=>'','title'=>'Notice'));
	      $notice ->display();			  
		  }		  	   
          $data = $_POST['data'];
		  $fids = $_POST['fids'];
		  $str='';
          foreach($fids as $key => $value )
		  {
		   $str.=$value.':';
		  }
		  
		  $data['fname']=$str;
		  		  
		  if($_FILES['postfile1']['tmp_name'])
	      { 		
	       include(ROOT_PATH.'/lib/upfile.lib.php');	  
		   $upfile = new Upfile('company/'.$GLOBALS['SCup']->SCup_user_msg['user_id']); 	  
	       $updata = $upfile->_batch_upfile('company');
	   	   if(!empty($updata)&&isset($updata[1]['path']))
		   {
		     $data['picurl']=$updata[1]['path'];
		   }
          }		  
		  
		  $data['uid'] = $GLOBALS['SCup']->SCup_user_msg['user_id'];
		  $data['username'] = $GLOBALS['SCup']->SCup_user_msg['data']['user_name'];		 		 		
		  $TB_company->post($data);		  
	      $notice = &get_message(array('msg'=>'Succes!','url'=>'','title'=>'Notice'));
	      $notice ->display();			  	
	   }
       if($action=='getfidsonslist')
	   { 
	      $fup = $_GET['fup'];
		  $class = $_GET['class'];
		  $ctype = $_GET['ctype'];
		  $Murl = SITE_URL; 
          header('Content-type: text/html; charset='.VIEW_CHARSET);	
	   
		  $companycategorydata = & $GLOBALS['SCup']->_get_category_data('company');
		  $icon_fup = true;	
		  foreach($companycategorydata as $key => $value)
		  {
		     if($value['parent_id']==$fup)
			 {
			  $icon_fup = false;	
			 }
		  }
	      if($icon_fup) echo "&nbsp;";
          $str='';
		  foreach($companycategorydata as $key => $value)
		  {
		     if($value['parent_id']==$fup)
			 {
		        $next='true';
		        $icon_fup = true;	
		        foreach($companycategorydata as $key1 => $value1)
		        {
		          if($value['cat_id']==$value1['parent_id'])
			      {
			       $icon_fup = false;	
			      }
		        }
				if($icon_fup || $class >= 4)
				{
				   $next = 'false';
				}
				$str.= "<div><a href=\"javascript:;\" onclick=\"changeClassName($class,this,".$value['cat_id'].",$next,$ctype ,\'$Murl\')\">".$value['cat_name']."</a></div>"; 				

			 }
		  }
	     $str=$str?$str:"&nbsp;";
	     echo '<script >parent.inputcontent(\''.$str.'\','.$class.');</script>';
	     exit;
	
       }	
		

	 	$companycategorydata = & $GLOBALS['SCup']->_get_category_data('company');	
        $this->assign('companycategorydata', $companycategorydata);	
		
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
			
        $this->assign('login_icon', $GLOBALS['SCup']->SCup_user_checking);	       
		 $this->assign('langtype', trim($GLOBALS['Lang']->_lang_tp));
	        $this->assign('site_url',SITE_URL);	
		$this->assign('bg_pic_url',SITE_URL.'/'.$GLOBALS['SCup']->SCup_name.'/view/'.VIEW_TYPE .'/style/'.CSS_TYPE.'/');	
		 $this->display('company/companypost.view.html');

    }

    function upfile()
    {
	 if(!isset($_POST["action"]))
	 {
	 $_POST["action"]='';
	 }
	 if(!isset($_GET['id']))
	 {
	 $_GET['id']='';
	 }
	 if(!isset($_GET["edit"]))
	 {
	 $_GET["edit"]='';
	 }	 
	 if(!isset($_GET["picurl"]))
	 {
	 $_GET["picurl"]='';
	 }	
	 if(!isset($_GET['jsfun']))
	 {
	 $_GET['jsfun']='';
	 }		 
	 if(!isset($_GET['putid']))
	 {
	 $_GET['putid']='';
	 }		 
	 if(!isset($_GET['uppic']))
	 {
	 $_GET['uppic']='';
	 }		 	
		$action = $_POST["action"];		
		$id = intval($_GET['id']);		
		$jsfun = $_GET['jsfun'];
		$uppic = $_GET['putid'];
		if(!empty($_GET['uppic']))
		{
		$uppic = $_GET['uppic'];		
		}	
		$edit = $_GET["edit"];
		$picurl = $_GET["picurl"];

        $this->assign('jsfun', $jsfun);		


        $this->assign('uppic', $uppic);		
	
				

        $this->assign('edit', $edit);		


        $this->assign('picurl', $picurl);


						
		if($action == 'post')
		{
			 if(!isset($_POST['jsfun']))
	 {
	 $_POST['jsfun']='';
	 }	
	 if(!isset($_POST['uppic']))
	 {
	 $_POST['uppic']='';
	 }		 
	 if(!isset($_POST["edit"]))
	 {
	 $_POST["edit"]='';
	 }		 
	 if(!isset($_POST["picurl"]))
	 {
	 $_POST["picurl"]='';
	 }	
	 if(!isset($_POST['id']))
	 {
	 $_POST['id']='';
	 }		 
		       $jsfun = $_POST['jsfun'];
		       $uppic = $_POST['uppic'];		
		       $edit = $_POST["edit"];
		       $picurl = $_POST["picurl"];
		 	   $id || $id = intval($_POST['id']);		
		       $filedname = trim(str_replace(array("UP_"),array(""),$uppic)); 
       
		       include(ROOT_PATH.'/lib/upfile.lib.php');	  
	           $upfile = new Upfile($this->type.'/'.$GLOBALS['SCup']->SCup_user_msg['user_id'].'/'.$id); 	  
	           $updata = $upfile->_batch_upfile($this->type);		 
		 		 
		       $newfile = $updata[1]['path'];
	       
			   if($edit=='editp' && $picurl)
			   {

			          $TB_new = &$this->_model('content');			    		 		 		
		              $TB_new->editpicurl($id,array("$filedname"=>$newfile),$this->table_id);
		              $pic_dir= ROOT_PATH . '/' . UPFILE_PATH . '/' . $picurl;
		              del_file($pic_dir);				   
			   }

			    if($edit=='edit' && $picurl)
		       {
		              $pic_dir= ROOT_PATH . '/' . UPFILE_PATH . '/' . $picurl;
		              del_file($pic_dir);			 
		       }
		
		      $pic_url = SITE_URL . '/' . UPFILE_PATH . '/' .$newfile;

	    echo "<img src='{$pic_url}' id='upsrc' width='100px' height='100px'><br/><A HREF='?app={$this->type}&act=upfile&edit=$edit&picurl=$newfile&id=$id&jsfun=$jsfun&uppic=$uppic'>修改图片</A>";

	    echo "<script>
				if(self==top){
					window.opener.$jsfun('$newfile','$uppic');
					window.self.close();
				}else{
					window.parent.$jsfun('$newfile','$uppic');
				}
		     </script>";
				
	    exit;		
		
		}

        $this->assign('id', $id);
	    $this->assign('app', $this->type);		    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');		
		
        $this->display('upfile.view.php');
    }



    function companymsg()
    {
      if(!isset($_GET['action']))$_GET['action']='';
	  $action = $_GET['action'];
       if($action=='editpost')
	   {
	   	  	   
          $data = $_POST['data'];
		  $fids = $_POST['fids'];
		  $oldfile = $_POST['oldfile'];
		  $str='';
          foreach($fids as $key => $value )
		  {
		   $str.=$value.':';
		  }
		  
		  $data['fname']=$str;
		  		  
		  if($_FILES['postfile1']['tmp_name'])
	      { 		
	       include(ROOT_PATH.'/lib/upfile.lib.php');	  
		   $upfile = new Upfile('company/'.$GLOBALS['SCup']->SCup_user_msg['user_id']); 	  
	       $updata = $upfile->_batch_upfile('company');
	   	   if(!empty($updata)&&isset($updata[1]['path']))
		   {
		     if($oldfile)
		     {
              del_file(ROOT_PATH . '/' . UPFILE_PATH . '/' . $oldfile);	
		     }		   
		     $data['picurl']=$updata[1]['path'];
		   }
          }		  
		  
		  $data['uid'] = $GLOBALS['SCup']->SCup_user_msg['user_id'];
		  $data['username'] = $GLOBALS['SCup']->SCup_user_msg['data']['user_name'];	
		  $TB_company= &$this->_model('company');	 		 		
		  $TB_company->editaction($data['uid'],$data);		  
	      $notice = &get_message(array('msg'=>'Succes!','url'=>'','title'=>'Notice'));
	      $notice ->display();			  	
	   }
       if($action=='getfidsonslist')
	   { 
	      $fup = $_GET['fup'];
		  $class = $_GET['class'];
		  $ctype = $_GET['ctype'];
		  $Murl = SITE_URL.'/company'; 
          header('Content-type: text/html; charset='.VIEW_CHARSET);	
	   
		  $companycategorydata = & $GLOBALS['SCup']->_get_category_data('company');
		  $icon_fup = true;	
		  foreach($companycategorydata as $key => $value)
		  {
		     if($value['parent_id']==$fup)
			 {
			  $icon_fup = false;	
			 }
		  }
	      if($icon_fup) echo "&nbsp;";
          $str='';
		  foreach($companycategorydata as $key => $value)
		  {
		     if($value['parent_id']==$fup)
			 {
		        $next='true';
		        $icon_fup = true;	
		        foreach($companycategorydata as $key1 => $value1)
		        {
		          if($value['cat_id']==$value1['parent_id'])
			      {
			       $icon_fup = false;	
			      }
		        }
				if($icon_fup || $class >= 4)
				{
				   $next = 'false';
				}
				$str.= "<div><a href=\"javascript:;\" onclick=\"changeClassName($class,this,".$value['cat_id'].",$next,$ctype ,\'$Murl\')\">".$value['cat_name']."</a></div>"; 				

			 }
		  }
	     $str=$str?$str:"&nbsp;";
	     echo '<script >parent.inputcontent(\''.$str.'\','.$class.');</script>';
	     exit;
	
       }	

		$TB_company= &$this->_model('company');		 		 		
		$companydata = $TB_company->oneshow($GLOBALS['SCup']->SCup_user_msg['user_id']);

        $this->assign('companydata', $companydata);			
        $fidsdata = $this->fidsstr($companydata['fname']);
        $this->assign('fidsdata', $fidsdata);						
		
	 	$companycategorydata = & $GLOBALS['SCup']->_get_category_data('company');	
			
        $this->assign('companycategorydata', $companycategorydata);	
		
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
			
        $this->assign('login_icon', $GLOBALS['SCup']->SCup_user_checking);	       
		$this->assign('langtype', trim($GLOBALS['Lang']->_lang_tp));
	    $this->assign('site_url',SITE_URL);	
		$this->assign('bg_pic_url',SITE_URL.'/'.$GLOBALS['SCup']->SCup_name.'/view/'.VIEW_TYPE .'/style/'.CSS_TYPE.'/');	
		$this->display('company/companymsg.view.html');

    }
    function companyrz()
    {
      if(!isset($_GET['action']))$_GET['action']='';
	  $action = $_GET['action'];
       if($action=='editpost')
	   {
	   	  	   
          $data = $_POST['data'];

		  $TB_company= &$this->_model('company');	 		 		
		  $TB_company->editaction($GLOBALS['SCup']->SCup_user_msg['user_id'],$data);		  
	      $notice = &get_message(array('msg'=>'Succes!','url'=>'','title'=>'Notice'));
	      $notice ->display();			  	
	   }	

		$TB_company= &$this->_model('company');		 		 		
		$companydata = $TB_company->oneshow($GLOBALS['SCup']->SCup_user_msg['user_id']);
        $this->assign('data', $companydata);	
				
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
			
        $this->assign('login_icon', $GLOBALS['SCup']->SCup_user_checking);	       
		 $this->assign('langtype', trim($GLOBALS['Lang']->_lang_tp));
	        $this->assign('site_url',SITE_URL);	
		$this->assign('bg_pic_url',SITE_URL.'/'.$GLOBALS['SCup']->SCup_name.'/view/'.VIEW_TYPE .'/style/'.CSS_TYPE.'/');	
		 $this->display('company/companyrz.view.html');

    }

    function nav()
    {
		$TB_nav = &$this->_model('nav'); 	 
		
		$navdata = $TB_nav->show($GLOBALS['SCup']->SCup_user_msg['user_id']);
		foreach($navdata as $key => $value)
		{
		 unset($navdata[$key]['config']);				
         $navdata[$key]['config'] = @unserialize($value['config']);		
		}
				
        $this->assign('navdata',$navdata);		
				
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
			
        $this->assign('login_icon', $GLOBALS['SCup']->SCup_user_checking);	       
		 $this->assign('langtype', trim($GLOBALS['Lang']->_lang_tp));
	        $this->assign('site_url',SITE_URL);	
		$this->assign('bg_pic_url',SITE_URL.'/'.$GLOBALS['SCup']->SCup_name.'/view/'.VIEW_TYPE .'/style/'.CSS_TYPE.'/');	
		 $this->display('company/companynavlist.view.html');

    }
    function navadd()
    {
      if(!isset($_GET['action']))$_GET['action']='';
	  $action = $_GET['action'];
       if($action=='addpost')
	   {
	     $data = $_POST['data'];		 
         $data_config = $data['config'];		 
		 unset($data['config']);
		 $data['user_id']=$GLOBALS['SCup']->SCup_user_msg['user_id'];	 
		 
		 $data['config'] = serialize($data_config);//@unserialize

		 $data['lang'] = trim($GLOBALS['Lang']->_lang_tp);		 
		 $data['scup'] = 'company';
	 
		 $TB_nav = &$this->_model('nav'); 	 
		
		 $TB_nav->post($data);
	      $notice = &get_message(array('msg'=>'Succes!','url'=>'','title'=>'Notice'));
	      $notice ->display();			 	   
	   }	
	

		$TB_company= &$this->_model('company');		 		 		
		$companydata = $TB_company->oneshow($GLOBALS['SCup']->SCup_user_msg['user_id']);
        $this->assign('companyid',$companydata['id']);			

				
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
			
        $this->assign('login_icon', $GLOBALS['SCup']->SCup_user_checking);	       
		 $this->assign('langtype', trim($GLOBALS['Lang']->_lang_tp));
	        $this->assign('site_url',SITE_URL);	
		$this->assign('bg_pic_url',SITE_URL.'/'.$GLOBALS['SCup']->SCup_name.'/view/'.VIEW_TYPE .'/style/'.CSS_TYPE.'/');	
		 $this->display('company/companynavadd.view.html');

    }	

    function navedit()
    {
      if(!isset($_GET['action']))$_GET['action']='';
	  $action = $_GET['action'];
       if($action=='editpost')
	   {


	     $data = $_POST['data'];

		 
		 $id = intval($data['id']);	 
		 
         $data_config = $data['config'];
		 
		 unset($data['config']);
		 
		 $data['config'] = serialize($data_config);//@unserialize		 
		 $data['lang'] = trim($GLOBALS['Lang']->_lang_tp);	
		 $data['scup'] = 'company';
		 $data['user_id']=$GLOBALS['SCup']->SCup_user_msg['user_id'];	 		 

		 $TB_nav = &$this->_model('nav'); 	 
		
		 $TB_nav->editaction($id,$data,$GLOBALS['SCup']->SCup_user_msg['user_id']);
  
	      $notice = &get_message(array('msg'=>'Succes!','url'=>'','title'=>'Notice'));
	      $notice ->display();			 	   
	   }	

       if($action=='del')
	   {

	     $id = $_GET['id'];
		 $TB_nav = &$this->_model('nav'); 	 
			 
		 $TB_nav->del($id,$GLOBALS['SCup']->SCup_user_msg['user_id']);	
  
	      $notice = &get_message(array('msg'=>'Succes!','url'=>'','title'=>'Notice'));
	      $notice ->display();			 	   
	   }
	
		$TB_company= &$this->_model('company');		 		 		
		$companydata = $TB_company->oneshow($GLOBALS['SCup']->SCup_user_msg['user_id']);
        $this->assign('companyid',$companydata['id']);			

		$id = $_GET['id'];
		$TB_nav = &$this->_model('nav');		
		$navdata = $TB_nav->oneshow($id,$GLOBALS['SCup']->SCup_user_msg['user_id']);
        $navdata['config'] = @unserialize($navdata['config']);
	    $this->assign('navdata', $navdata);	        						
				
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
			
        $this->assign('login_icon', $GLOBALS['SCup']->SCup_user_checking);	       
		 $this->assign('langtype', trim($GLOBALS['Lang']->_lang_tp));
	        $this->assign('site_url',SITE_URL);	
		$this->assign('bg_pic_url',SITE_URL.'/'.$GLOBALS['SCup']->SCup_name.'/view/'.VIEW_TYPE .'/style/'.CSS_TYPE.'/');	
		 $this->display('company/companynavedit.view.html');

    }	

    function links()
    {
		
		
		$TB_links = &$this->_model('links');  
		
		$linksdata = $TB_links->show($GLOBALS['SCup']->SCup_user_msg['user_id']);
				
        $this->assign('linksdata',$linksdata);		
	    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
			
        $this->assign('login_icon', $GLOBALS['SCup']->SCup_user_checking);	       
		 $this->assign('langtype', trim($GLOBALS['Lang']->_lang_tp));
	        $this->assign('site_url',SITE_URL);	
		$this->assign('bg_pic_url',SITE_URL.'/'.$GLOBALS['SCup']->SCup_name.'/view/'.VIEW_TYPE .'/style/'.CSS_TYPE.'/');
		
        $this->display('company/companylinkslist.view.html');
    }

    function linksadd()
    {
		
		
      if(!isset($_GET['action']))$_GET['action']='';
	  $action = $_GET['action'];
       if($action=='addpost')
	   {
	     $data = $_POST['data'];
		 unset($data['path']);
		 $data['user_id']=$GLOBALS['SCup']->SCup_user_msg['user_id'];
		 if($_FILES['postfile1']['tmp_name'])
	     { 		 			 
	     include(ROOT_PATH.'/lib/upfile.lib.php');	  
	     $upfile = new Upfile('company/'.$GLOBALS['SCup']->SCup_user_msg['user_id'].'/links'); 	  
	     $updata = $upfile->_batch_upfile('links');		 
		 if(!isset($updata[1]['path']))	
		 {
		 $updata[1]['path'] ='';
		 }			 		 
		 $data['path'] = $updata[1]['path'];		 
	 	 }	 
		 $TB_links = &$this->_model('links');  
	 
		
		 $TB_links->post($data);

	      $notice = &get_message(array('msg'=>'Succes!','url'=>'','title'=>'Notice'));
	      $notice ->display();			 	   
	   }	

		$TB_company= &$this->_model('company');		 		 		
		$companydata = $TB_company->oneshow($GLOBALS['SCup']->SCup_user_msg['user_id']);
        $this->assign('companyid',$companydata['id']);	
			    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
			
        $this->assign('login_icon', $GLOBALS['SCup']->SCup_user_checking);	       
		 $this->assign('langtype', trim($GLOBALS['Lang']->_lang_tp));
	        $this->assign('site_url',SITE_URL);	
		$this->assign('bg_pic_url',SITE_URL.'/'.$GLOBALS['SCup']->SCup_name.'/view/'.VIEW_TYPE .'/style/'.CSS_TYPE.'/');
		
        $this->display('company/companylinksadd.view.html');
    }

    function linksedit()
    {
		
      if(!isset($_GET['action']))$_GET['action']='';
	  $action = $_GET['action'];
       if($action=='editpost')
	   {

	     $data = $_POST['data'];
		 unset($data['path']);
		 
		 $id = intval($data['id']);	 
		 $TB_links = &$this->_model('links');  		 		 		
		 $picdata = $TB_links->oneshow($id,$GLOBALS['SCup']->SCup_user_msg['user_id']);
		 
		 if($_FILES['postfile1']['tmp_name'])
	     { 		 
	     include(ROOT_PATH.'/lib/upfile.lib.php');	  
	     $upfile = new Upfile('company/'.$GLOBALS['SCup']->SCup_user_msg['user_id'].'/links'); 	  
	     $updata = $upfile->_batch_upfile('links');
		 
		 if($picdata['images_dir'] && $updata)
		 {
		 $pic_dir = ROOT_PATH . '/' . UPFILE_PATH . '/' . $picdata['images_dir'];
		 del_file($pic_dir);			 
		 } 
		 if(empty($updata))
		 {
		 $data['path'] = $picdata['images_dir'];		 
		 }
		 else
		 {
		 $data['path'] = $updata[1]['path'];		 
		 }
		 }
		
		 $TB_links->editaction($id,$data,$GLOBALS['SCup']->SCup_user_msg['user_id']);
  
	      $notice = &get_message(array('msg'=>'Succes!','url'=>'','title'=>'Notice'));
	      $notice ->display();			 	   
	   }
       if($action=='del')
	   {

	     $id = $_GET['id'];
		 $TB_links = &$this->_model('links');  
		 		
		 $linksdata = $TB_links->oneshow($id,$GLOBALS['SCup']->SCup_user_msg['user_id']);
		 
		 $pic_dir = ROOT_PATH . '/' . UPFILE_PATH . '/' . $linksdata['images_dir'];
		 del_file($pic_dir);
		 
		 $TB_links->del($id,$GLOBALS['SCup']->SCup_user_msg['user_id']);	
  
	      $notice = &get_message(array('msg'=>'Succes!','url'=>'','title'=>'Notice'));
	      $notice ->display();			 	   
	   }	   
	   		
	    $id = $_GET['id'];	
		
		$TB_links = &$this->_model('links');  
		
		$picdata = $TB_links->oneshow($id,$GLOBALS['SCup']->SCup_user_msg['user_id']);
        $this->assign('picdata',$picdata);		
	    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
			
        $this->assign('login_icon', $GLOBALS['SCup']->SCup_user_checking);	       
		 $this->assign('langtype', trim($GLOBALS['Lang']->_lang_tp));
	        $this->assign('site_url',SITE_URL);	
		$this->assign('bg_pic_url',SITE_URL.'/'.$GLOBALS['SCup']->SCup_name.'/view/'.VIEW_TYPE .'/style/'.CSS_TYPE.'/');
		
        $this->display('company/companylinksedit.view.html');
    }
	
    function view()
    {
	
	   $this->view_scup_dir = ROOT_PATH.'/company/view'; 
	    $TB_company = &$this->_model('company'); 	
	    $companydata = $TB_company->oneshow($GLOBALS['SCup']->SCup_user_msg['user_id']);
		$setingconfig = unserialize($companydata['setingconfig']);
		
	   	$old_viewstyle= $setingconfig['view_type'];	
	   	$old_cssstyle= $setingconfig['css_type'];
		
        $this->assign('old_viewstyle',$old_viewstyle);
        $this->assign('old_cssstyle', $old_cssstyle);
		
       if(!isset($_GET['action']))$_GET['action']='';
	   $action = $_GET['action'];
       if($action=='lstatus')
	   {
		 $data=array();  
	     $id = $_GET['id'];
		 $data['view_type'] = $id;
		 $data['css_type'] = 'style1';
		 
         $this->viewset($data);	 
		 $notice = &get_message(array('msg'=>"修改成功!",'url'=>'?app=company&act=view','title'=>'Notice'));
		 $notice ->display();		   
	   }
       if($action=='setcss')
	   {
		 $data=array();  
	     $css = $_GET['v'];
	     $view = $_GET['view'];	
         if(empty($css)||empty($view))
		 {
		 $notice = &get_message(array('msg'=>"参数有错!",'url'=>'?app=company&act=view','title'=>'Notice'));
		 $notice ->display();		 
		 }		 
         if($view!=$old_viewstyle)
		 {
		 $notice = &get_message(array('msg'=>"你选择的不是本模板的样式!",'url'=>'?app=company&act=view','title'=>'Notice'));
		 $notice ->display();		 
		 }		 	 
		 $data['css_type'] = $css;
		 
         $this->viewset($data);	 
		 $notice = &get_message(array('msg'=>"修改成功!",'url'=>'?app=company&act=view','title'=>'Notice'));
		 $notice ->display();		   
	   }	   
	   		
		
        $temparray = array();
        $temparray1 = array();
        $temparray = get_all_dirname($this->view_scup_dir);
        
		foreach($temparray as $key => $value)
		{
		  if(is_file($this->view_scup_dir.'/'.$value.'/config/config.inc'))
		  {
               $this->view_data[$value] = include($this->view_scup_dir.'/'.$value.'/config/config.inc');
               $temparray1 = get_all_dirname($this->view_scup_dir.'/'.$value.'/style');
			   foreach($temparray1 as $key1 => $value1)
			   {
		           if(is_file($this->view_scup_dir.'/'.$value.'/style/'.$value1.'/config.inc'))
		           {
                    $this->view_data[$value]['style'][$value1] = include($this->view_scup_dir.'/'.$value.'/style/'.$value1.'/config.inc');
			   		          		  
		           }				   
			   
			   }			   
			   if(!isset($this->view_data[$value]['style']))
			   {
			   $this->view_data[$value]['style'] = array();
			   }	          		  
		  }
		  
		}

        $this->assign('infos', $this->view_data);	
	    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
			
        $this->assign('login_icon', $GLOBALS['SCup']->SCup_user_checking);	       
		 $this->assign('langtype', trim($GLOBALS['Lang']->_lang_tp));
	        $this->assign('site_url',SITE_URL);	
		$this->assign('bg_pic_url',SITE_URL.'/'.$GLOBALS['SCup']->SCup_name.'/view/'.VIEW_TYPE .'/style/'.CSS_TYPE.'/');
		
        $this->display('company/companyview.view.html');
    }	
    function viewset($data)
    {

		$TB_set = &$this->_model('setting'); 	

		$temp_setdata = array();

		$user_id = $GLOBALS['SCup']->SCup_user_msg['user_id'];
	    $TB_company = &$this->_model('company'); 	
	    $companydata = $TB_company->oneshow($user_id);
		$setingconfig = unserialize($companydata['setingconfig']);
	
		 $setdata = $TB_set->show();
		foreach($setdata as $key => $value)
		{
           $temp_setdata[$value['keyname']] = $value['value'];		   
		}
		foreach($setingconfig as $key => $value)
		{
           $temp_setdata[$key] = $value;	   
		}		
		
		foreach($data as $key => $value)
		{
           $temp_setdata[$key] = $value;	   
		}

	
				
	    $TB_company->editsetting($user_id,serialize($temp_setdata)); 	 
		$str = '';		 
         foreach ($temp_setdata as $key => $value)
         {
               if (is_string($value) || is_numeric($value) || is_bool($value) || is_null($value))
               {
                    $str .= "define('".strtoupper($key)."','".$value."');\r\n";

                }
         }		 		 	    	
		 write_file(ROOT_PATH . '/data/companyconfig/config_'.$companydata['id'].'.inc.php',"<?php\r\n".$str.'?>');	
		 
     
    }

		
    function fidsstr($str='')
    {
        $array = explode(':',$str);
		return del_empty_var($array);

    }   
	
	
    function qiyefenlei()
    {

	
        $company_data = include(ROOT_PATH . '/data/category/category_company.php'); 

		$this->assign('company_data', $company_data);

	    
        $this->assign('view_charset', VIEW_CHARSET);
	
        $this->assign('langtype', trim($GLOBALS['Lang']->_lang_tp));
						
        $this->assign('site_url', SITE_URL);
				
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);
		$this->assign('bg_pic_url',SITE_URL.'/'.$GLOBALS['SCup']->SCup_name.'/view/'.VIEW_TYPE .'/style/'.CSS_TYPE.'/');	
        $this->assign('login_icon', $GLOBALS['SCup']->SCup_user_checking);		

		
        $this->display('qiyefenlei.view.html');
    } 

     function qiyefenleilist()
    {

        if(!isset($_GET['id']))
		{
		$_GET['id'] ='';
		}
	    $id = $_GET['id']; 

		$TB_new = &$this->_model('company');
				
        $data = $TB_new->qiyeshow('',$id);	

        $this->assign('lw_data', $data['data']);		
		$this->assign('lw_page', $data['page']);	

		
        $company_data = include(ROOT_PATH . '/data/category/category_company.php'); 

		$this->assign('company_data', $company_data);

        $this->assign('view_charset', VIEW_CHARSET);
	
						
        $this->assign('site_url', SITE_URL);
				
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);
		$this->assign('bg_pic_url',SITE_URL.'/'.$GLOBALS['SCup']->SCup_name.'/view/'.VIEW_TYPE .'/style/'.CSS_TYPE.'/');	
        $this->assign('login_icon', $GLOBALS['SCup']->SCup_user_checking);		

        $this->display('qiyefenleilist.view.html');
    } 	
	
	
	
	
}






?>